package io.github.shang11925.sbvuewelearn.controller;

import io.github.shang11925.sbvuewelearn.dto.TextContentsDTO;
import io.github.shang11925.sbvuewelearn.entity.TextContents;
import io.github.shang11925.sbvuewelearn.response.TextContentsResponse;
import io.github.shang11925.sbvuewelearn.service.TextContentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin("http://localhost:5173/")
public class TextContentsController {
    @Autowired
    TextContentsService textContentsService;

    @GetMapping("/list-text_contents/{sectionId}")
    public TextContentsResponse list(@PathVariable Long sectionId){
        List<TextContents> textContents = textContentsService.findBySectionId(sectionId);
        TextContentsResponse textContentsResponse = new TextContentsResponse();
        textContentsResponse.setTextContents(textContents);
        return textContentsResponse;
    }

    @PostMapping("add-text_contents")
    public void add(@RequestBody TextContentsDTO textContentsDTO){textContentsService.add(textContentsDTO);}
}